package com.shop.job;

import com.shop.mapper.InFormMapper;
import com.shop.model.dto.ScheduleLog;
import com.shop.schedule.MyScheduler;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author : WanS
 * @date : 10:34 2020/11/24
 */
@Slf4j
public class DateTimeJob extends QuartzJobBean {
    @Resource
    private InFormMapper inFormMapper;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //开始时间
        Date startTime = new Date();
        String error = null;
        try {
            log.info("执行定时任务中: "+new Date().toLocaleString());
        } catch (Exception e) {
            e.printStackTrace();
            error = e.getMessage();
        }
        //结束时间
        Date endTime = new Date();
        ScheduleLog log = new ScheduleLog();
        int id = inFormMapper.getScheduleId(DateTimeJob.class.getName());
        MyScheduler.insertLog(startTime, error, endTime, id, inFormMapper);
    }
}
